<!doctype html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="shortcut icon" th:href="@{../../favicon.ico}" type="image/x-icon" />
    <link rel="stylesheet" th:href="@{../../assets/css/font.css}">
    <link rel="stylesheet" th:href="@{../../assets/css/xadmin.css}">
    <link rel="stylesheet" th:href="@{../../assets/lib/toast/css/toast.style.css}">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{../../assets/lib/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{../../assets/js/xadmin.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{../../assets/lib/toast/js/toast.script.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{../../assets/lib/date/dateformat.js}" charset="utf-8"></script>
    <title>管理员-X-admin2.0</title>

</head>
<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="javascript:void(0)">系统管理</a>
        <a>
          <cite>角色</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">

    </a>
</div>
<div class="x-body">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so reloadTable">
            <input class="layui-input" placeholder="角色编码" type="text" name="isCode" id="isCode">
            <input class="layui-btn" data-type="reload" type="button" value="查询" id="reloadBtn">
        </form>
    </div>
    <table class="layui-table" lay-data="{height:600, even: true,url:'/system/role/role-list.json', page:true,toolbar: '#headToolbar', id:'systemRoleTable'}" lay-filter="systemRoleTable">
        <thead>
        <tr>
            <th lay-data="{fixed: 'left', width:80,align:'center', templet: '#indexTemplet'}">序号</th>
            <th lay-data="{field:'name'}">角色名称</th>
            <th lay-data="{field:'isCode'}">角色编码</th>
            <th lay-data="{field:'state',width:100,align:'center',templet:'#stateTemplet'}">状态</th>
            <th lay-data="{fixed: 'right', width:220, fixed: 'right',align:'center', toolbar: '#operatorBar'}">操作</th>
        </tr>
        </thead>
    </table>
</div>
<script type="text/html" id="indexTemplet">
    {{d.LAY_TABLE_INDEX+1}}
</script>
<script type="text/html" id="headToolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-normal" lay-event="createSystemRole">添加角色</button>
    </div>
</script>
<script type="text/html" id="operatorBar">
    {{#  if(d.state == 'N'){ }}
    &nbsp;&nbsp;<a lay-event="editState" th:title="启用"><i class="iconfont">&#xe6ad;</i></a>
    {{#  } else { }}
    &nbsp;&nbsp;<a lay-event="editState" th:title="禁用"><i class="iconfont">&#xe69a;</i></a>
    {{#  } }}
    &nbsp;&nbsp;<a lay-event="delete" th:title="删除"><i class="iconfont">&#xe69d;</i></a>
    &nbsp;&nbsp;<a lay-event="setup" th:title="配置权限"><i class="iconfont">&#xe6a7;</i></a>
</script>
<script type="text/html" id="stateTemplet">
    {{#  if(d.state == 'N'){ }}
    <span class="layui-bg-red"> 禁用 </span>
    {{#  } else { }}
    <span class="layui-bg-green"> 启用 </span>
    {{#  } }}
</script>
<script>
    layui.use(['laydate','table'], function(){

        $ = layui.jquery;
        var laydate = layui.laydate,table = layui.table;


        $('.reloadTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        //重载表格
        var $ = layui.$, active = {
            reload: function(){
                var isCode = $('#isCode').val();
                //执行重载
                table.reload('systemRoleTable', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        isCode:isCode
                    }
                });
            }
        };

        //监听工具条
        table.on('tool(systemRoleTable)', function(obj){

            var data = obj.data;
            var layEvent = obj.event;
            console.log(data);

            if(layEvent === 'delete'){ //删除
                layer.confirm('是否删除【'+ data.name +'】，删除之后不能恢复，请确认', function(index){
                    $.ajax({
                        url: "/system/role/role-delete.json",
                        type:"POST",
                        data :data,
                        success: function(result){
                            if (result.status) {
                                layer.msg("操作成功");
                                document.getElementById("reloadBtn").click();
                            }else{
                                layer.msg(result.msg);
                            }
                        },
                        error: function () {
                            layer.msg("修改错误，请联系开发人员进行排查");
                        }
                    });
                });
            } else if(layEvent === 'editState'){ //编辑
                layer.confirm('是否修改【'+ data.name +'】的状态，请确认', function(index){
                    $.ajax({
                        url: "/system/role/role-updateState.json",
                        type:"POST",
                        data :data,
                        success: function(result){
                            if (result.status) {
                                layer.msg("操作成功");
                                document.getElementById("reloadBtn").click();
                            }else{
                                layer.msg(result.msg);
                            }
                        },
                        error: function () {
                            layer.msg("修改错误，请联系开发人员进行排查");
                        }
                    });
                });
            }else if(layEvent === 'setup'){ //配置权限
                x_admin_show("【"+data.name+"】配置权限","/system/role/role-setupPermission.html?roleId="+data.id,600,400);
            }
        });

        //头工具栏事件
        table.on('toolbar(systemRoleTable)', function(obj){
            switch(obj.event){
                case 'createSystemRole':
                    x_admin_show("新增成员","/system/role/role-create.html",600,400);
                    break;
            }
        });
    });
</script>
</body>

</html>